package main

import (
	"gitee.com/zhucheer/orange/queue"
	"time"
	"fmt"
	"github.com/json-iterator/go"
)

type Student struct{
	Id string
	Name string
	Birth string
	Sex string
	CreateTime time.Time
	UpdateTime time.Time
	CourseList []*Course
}

type Course struct{
	Id string
	Name string
	TeacherId string
	CreateTime time.Time
	UpdateTime time.Time
	Score Score
	Teacher Teacher
}

type Teacher struct{
	Id string
	Name string
	CreateTime time.Time
	UpdateTime time.Time
}

type Score struct{
	StudentId string
	CourseId  string
	Score string
	CreateTime time.Time
	UpdateTime time.Time
}

func main(){
	// // 注册生产者 填入broker节点,group名称,重试次数信息
	// mqProducerClient := queue.RegisterRocketProducerMust([]string{"127.0.0.1:9876"}, "test", 1)

	// 注册消费者 填入broker节点,group名称信息
	mqConsumerClient:= queue.RegisterRocketConsumerMust([]string{"127.0.0.1:9876"}, "test")

	// go func() {
	//    for i:=0;i<10;i++{
	//       // 向队列发送一条消息 填入消息队列topic和消息体信息
	//       ret,_:=mqProducerClient.SendMsg("topicTest", "Hello mq~~")
	//       fmt.Println("========producer push one message====", ret.MsgId)

	//       time.Sleep(time.Second)
	//    }

	// }()


	// 执行消费者监听 填入消息队列topic
	mqConsumerClient.ListenReceiveMsgDo("topicTest", func(mqMsg queue.MqMsg) {
		// 收到一条消息
		fmt.Println("receive====>",mqMsg.MsgId, mqMsg.BodyString())

		var s []*Student
		jerr := jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(mqMsg.BodyString()), &s)
		if jerr != nil{
			fmt.Println("jerr：", jerr)
		}
		fmt.Println("s：", s)

	})

	//time.Sleep(20*time.Second)
	select {}

}

